function SignReport_Data(data) {
	var buffer = new StringBuffer();
	buffer.append('<div class="signstastics border-bottom">');
		buffer.append('<div class="date"><div class="titles">日期</div><div class="ui-border time"><div id="curryear" class="year">2016年</div><div id="currmonth" class="month">7<font>月</font></div></div></div>');
		buffer.append('<div class="stastics ui-border-top-radius">');
			buffer.append('<div class="manqin ui-border-b">');
			buffer.append('<div id="manpanel" class="man"><div class="titles">满勤天数</div><div id="manqin" class="days">0 <font>天</font></div></div>');
			buffer.append('<div id="waipanel" class="man ui-border-l" style="display:none;"><div class="titles">外勤天数</div><div id="waiqin" class="days">0 <font>天</font></div></div>');
			buffer.append('</div>');
			buffer.append('<div class="nomanqin">');
				buffer.append('<div class="chidao ui-border-r"><div class="titles">迟到</div><div id="chidao" class="days">0 <font>次</font></div></div>');
				buffer.append('<div class="chidao ui-border-r"><div class="titles">早退</div><div id="zaotui" class="days">0 <font>次</font></div></div>');
				buffer.append('<div class="chidao"><div class="titles">缺勤</div><div id="queqin"  class="days">0 <font>次</font></div></div>');
			buffer.append('</div>');
		buffer.append('</div>');
	buffer.append('</div>');
	$(data).each(function(i,info){
		buffer.append('<div class="signlist border-bottom" userid="'+info.UserID+'" date="'+info.CreateDate.ToDate()+'" state="'+info.State+'" bak="'+info.Bak+'"><div class="date">'+info.CreateDate.ToMonth()+'</div><div class="name">'+info.RealName+'</div><div class="state '+(info.State.indexOf("满勤")>-1?"greens":"reds")+'">'+info.State+'</div><div class="bak">'+info.Bak+'</div></div>');
	});
	return buffer.toString();
};
function SignWork_Data(data) {
	var buffer = new StringBuffer();
	buffer.append('<div class="signstastics border-bottom">');
		buffer.append('<div class="date"><div class="titles">日期</div><div class="ui-border time"><div id="curryear" class="year">2016年</div><div id="currmonth" class="month">7<font>月</font></div></div></div>');
		buffer.append('<div class="stastics ui-border-top-radius">');
			buffer.append('<div class="manqin ui-border-b">');
			buffer.append('<div id="manpanel" class="man"><div class="titles">出勤天数</div><div id="chuqin" class="days">0 <font>天</font></div></div>');
			buffer.append('</div>');
			buffer.append('<div class="nomanqin">');
				buffer.append('<div class="chidao ui-border-r"><div class="titles">满勤</div><div id="manqin" class="days">0 <font>次</font></div></div>');
				buffer.append('<div class="chidao ui-border-r"><div class="titles">迟到</div><div id="chidao" class="days">0 <font>次</font></div></div>');
				buffer.append('<div class="chidao" style="border-right:0px;"><div class="titles">早退</div><div id="zaotui"  class="days">0 <font>次</font></div></div>');
			buffer.append('</div>');
		buffer.append('</div>');
	buffer.append('</div>');
	$(data).each(function(i,info){
		if(info.State!="--"){
			buffer.append('<div class="signlist border-bottom" userid="'+info.UserID+'" date="'+info.CreateDate.ToDate()+'" state="'+info.State+'" bak="'+info.Bak+'"><div class="date">'+info.CreateDate.ToMonth()+'</div><div class="name">'+info.RealName+'</div><div class="state '+(info.State.indexOf("满勤")>-1?"greens":"reds")+'">'+info.State+'</div><div class="bak">'+info.Bak+'</div></div>');
		}
	});
	return buffer.toString();
};
function SignDetail_Data(data,date,state,bak) {
	var buffer = new StringBuffer();
	buffer.append('<div class="signdetail"><div class="line"><div class="name">日期：</div><div class="value">'+date+'</div></div><div class="line"><div class="name">状态：</div><div class="value">'+state+'</div></div><div class="line"><div class="name">备注：</div><div class="value">'+bak+'</div></div><div class="line" style="height:20px; padding-top:20px;"><div class="name">记录：</div></div></div>');
	$(data).each(function(i,info){
		buffer.append('<div class="signrecord border-bottom"><div class="address">'+info.Address + '</div><div class="date">'+info.SignTime+'</div>');
		if(info.State==9){
			buffer.append('<div class="scustomer">'+info.CustomerName + '</div><div class="svisit">外勤签到</div>');
		}
		buffer.append('<div class="aimg">');
		$.each(info.AnnexList,function(k,img){
			var right=k%3==2?0:5;
		buffer.append('<figure class="asquare" style="width:'+(swidth-30)/3+'px; heigth:'+(swidth-30)/3+'px; margin-right:'+right+'px; float:left; display:block;" itemscope itemtype="http://schema.org/ImageObject"><a src="'+img.Img1000+'" itemprop="contentUrl" data-size="'+img.Width+'x'+img.Height+'"><img src="' + img.Img200 + '" width="'+(swidth-30)/3+'" height="'+(swidth-30)/3+'" itemprop="thumbnail" alt="Image description"/></a></figure>');
		});
		buffer.append('</div>');
		buffer.append('<div class="bak">'+info.Bak+'</div></div>');
	});
	return buffer.toString();
};
function Sign_Detail(userids,date,state,bak){
	OpenWindow(3,"打卡记录详情","",null);
	var data={};
	data.act="Find_SignDetail";
	data.date=date;
	data.userid=userids;
	data.comid=comid;
	data.source=source;
	data.sign=GetSign(data.act);
	mui.getJSON(index_domain, data, function(json) {
		if(json.data.length>0)
		{
			$("#contentlist3").html(SignDetail_Data(json.data,date,state,bak));
			initPhotoSwipeFromDOM('.signrecord'); 
		}else
		{
			$("#loading3").html("主人，没有您的打卡记录");
		}
	});
};

function Receive_SignReport(userids,pageindex,year,month)
{
	var date=new Date();
	if(!year)
	{
		year=date.getFullYear();
		month=date.getMonth()+1;
	}
	
	var data = {};
			data.act = "Find_SignReport";
			data.userid=userids;
			data.comid=comid;
			data.pageindex=pageindex;
			data.state=-1;
			data.type=-1;
			data.source=source;
			data.year=year;
			data.month=month;
			data.pagesize=PAGE_SIZE10;
			data.sign=GetSign(data.act);
			
			mui.getJSON(index_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					$("#contentlist2").html(SignReport_Data(json.data.list,data.tableid));
					$("#manqin").html(json.data.manqin+" <font>天</font>");
					if(json.data.waiqin>0){
						$("#waiqin").html(json.data.waiqin+" <font>天</font>");
						$("#manpanel").css("width","50%");
						$("#waipanel").css("width","50%").show();
					}
					$("#chidao").html(json.data.chidao+" <font>次</font>");
					$("#zaotui").html(json.data.zaotui+" <font>次</font>");
					$("#queqin").html(json.data.queqin+" <font>次</font>");
					$("#curryear").html(year+"年");
					$("#currmonth").html(month+"<font>月</font>");
					setTimeout(function(){
						Init_SignReport();
						
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
				}else
				{
					$("#loading2").html("没有更多了");
				}
         		var pageindex = parseInt($("#divmsg2").attr("pageindex"))+1;
         		$("#divmsg2").attr("pageindex",pageindex);
			});
};

function Receive_SignWork(userids,pageindex,year,month)
{
	var date=new Date();
	if(!year)
	{
		year=date.getFullYear();
		month=date.getMonth()+1;
	}
	
	var data = {};
			data.act = "Find_SignWork";
			data.userid=userids;
			data.comid=comid;
			data.pageindex=pageindex;
			data.state=-1;
			data.type=-1;
			data.source=source;
			data.year=year;
			data.month=month;
			data.pagesize=PAGE_SIZE10;
			data.sign=GetSign(data.act);
			
			mui.getJSON(index_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					$("#contentlist2").html(SignWork_Data(json.data.list,data.tableid));
					$("#chuqin").html(json.data.chuqin+" <font>天</font>");
					$("#manqin").html(json.data.manqin+" <font>天</font>");
					$("#chidao").html(json.data.chidao+" <font>次</font>");
					$("#zaotui").html(json.data.zaotui+" <font>次</font>");
					$("#curryear").html(year+"年");
					$("#currmonth").html(month+"<font>月</font>");
					setTimeout(function(){
						Init_SignReport();
						
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
				}else
				{
					$("#loading2").html("没有更多了");
				}
         		var pageindex = parseInt($("#divmsg2").attr("pageindex"))+1;
         		$("#divmsg2").attr("pageindex",pageindex);
			});
};

function Init_SignReport(){
	mui("#contentlist2").on("tap",".signlist",function() {
		Sign_Detail($(this).attr("userid"),$(this).attr("date"),$(this).attr("state"),$(this).attr("bak")); 
	});
};


function Show_Month(fun){
	var buffer = new StringBuffer();
	var date=new Date();
	var year=date.getFullYear();
	var lastyear=year-1;
	var month=date.getMonth()+1;
	buffer.append('<div class="yearandmonth">');
		buffer.append('<div class="year">'+year+'</div>');
		buffer.append('<div class="month">');
		for(var i=1;i<=month;i++)
		{
			buffer.append('<div class="square ui-border-radius" year="'+year+'" month="'+i+'">'+i+'月</div>');
		}
		buffer.append('</div>');
		buffer.append('<div class="year" style="margin-top:10px;">'+lastyear+'</div>');
		buffer.append('<div class="month">');
		for(var i=1;i<=12;i++)
		{
			buffer.append('<div class="square ui-border-radius" year="'+lastyear+'" month="'+i+'">'+i+'月</div>');
		}
		buffer.append('</div>');
	buffer.append('</div>');
	OpenMeng2(buffer.toString());
	
	
	mui(".yearandmonth").on("tap",".square",function(){
		fun($(this).attr("year"),$(this).attr("month"));
		CloseMeng2();
	});
};




function SignStastics_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div class="signlist border-bottom" style="background-color:#f3f3f3; position:fixed; z-index:99; top:45px;"><div class="headimg"></div><div class="realname">姓名</div><div class="manqin">满勤</div><div class="chidao">迟到</div><div class="zaotui">早退</div><div class="queqin">缺勤</div><div class="banqin">半勤</div></div>');
	return buffer.toString();
};

var years,months;
function SignStastics_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="signlist border-bottom" userid="'+info.UserID+'"><div class="headimg"><img src="'+info.HeadImg+'" /></div><div class="realname">'+info.RealName+'</div><div class="manqin greens">'+info.ManQin+'</div><div class="chidao reds">'+info.ChiDao+'</div><div class="zaotui reds">'+info.ZaoTui+'</div><div class="queqin reds">'+info.QueQin+'</div><div class="banqin reds">'+info.BanQin+'</div></div>');
	});
	return buffer.toString();
};
function Receive_SignStastics(pageindex,year,month)
{
	var date=new Date();
	if(!year)
	{
		year=date.getFullYear();
		month=date.getMonth()+1;
	}
	years=year;months=month;
	$("#divmsg1 .title .name").html(month+"月打卡报表");
	var data = {};
			data.act = "Find_SignStastics";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.year=year;
			data.month=month;
			data.sign=GetSign(data.act);
			
			mui.getJSON(index_domain, data, function(json) {
				if(json.data.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist1").html(SignStastics_Data(json.data));
					}else{
						$("#contentlist1").append(SignStastics_Data(json.data));
					}
					setTimeout(function(){
						Init_SignStastics();
						myScroll1.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.length!=data.pagesize)
					{
						$("#loading1").html("");
					}else{
						$("#loading1").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					if(pageindex==1)
					{
						$("#contentlist1").html("");
						$("#loading1").html("主人，没有找到您需要的数据");
					}else
					{
						$("#loading1").html("没有更多了");
					}
				}
         		pageindex = parseInt($("#divmsg1").attr("pageindex"))+1;
         		$("#divmsg1").attr("pageindex",pageindex);
			});
};

function Init_SignStastics(){
	mui("#contentlist1").off("tap",".signlist"); //必须有
	mui("#contentlist1").on("tap",".signlist",function() {
		var userids=$(this).attr("userid");
		OpenWindow(2,"打卡记录列表","<div class='rili'><img src='img/rili.png' width='20'/></div>",function(){
			$("#divmsg2 .title").css("z-index","101");
			Show_Month(function(year,month){
				$("#contentlist2").html('<div id="loading2" class="loading"><img src="img/loading.gif"/></div>');
				Receive_SignReport(userids,1,year,month);
			});
		});
		Receive_SignReport(userids,1,years,months);
		
	});
};